package com.jp.reflection;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * 反射是一种专门为静态语言提供的技术，用于在程序运行时动态地改变程序的状态和行为
 * <p>
 * 反射机制：运行时，对于任意一个类或对象，都能够调用它的任意字段和方法
 */
public class Main {
    public static void main(String[] args) {
        System.out.println("Main");
        // classInfo();
       // formatInfo();

        Order order = new Order();
        order.setUserId(88888L);

        List<Order> now = Now(Collections.singletonList(order));

    }


    static void classInfo() {
        printClassInfo("".getClass());
        printClassInfo(Runnable.class);
        printClassInfo(java.time.Month.class);
        printClassInfo(String[].class);
        printClassInfo(int.class);
    }

    static void printClassInfo(Class<?> cls) {
        System.out.println("###########");
        System.out.println("Class name: " + cls.getName());
        System.out.println("Simple name：" + cls.getSimpleName());
        if (cls.getPackage() != null) {
            System.out.println("Package name：" + cls.getPackage().getName());
        }

        System.out.println("is interface：" + Arrays.toString(cls.getInterfaces()));
        System.out.println("is enum：" + cls.isEnum());
        System.out.println("is array：" + cls.isArray());
        System.out.println("is primitive：" + cls.isPrimitive());
        System.out.println("###########");
    }

    public static List<? extends CommonUser> test(List<? extends CommonUser> list) {
        for (CommonUser commonUser : list) {
            Long userId = commonUser.getUserId();
            if (userId != null) {
                commonUser.setUserName("Name");
            }
        }
        return list;
    }

    public static <T extends Collection<E>, E extends CommonUser> T Now(T coll) {
        for (E e : coll) {
            System.out.println(e.getUserId());
        }
        return null;
    }

    public static void formatInfo() {
        Order order = new Order();
        order.setUserId(8L);

        List<Order> list = Collections.singletonList(order);

        test(list).forEach(System.out::println);


    }
}
